// @Author maotao
// Created by tao on 24-9-16.
//

#include <stdlib.h>
#include <oled.h>
#include <Bird.h>

#define MIN(a,b) (((a)<(b))?(a):(b))

static unsigned int _bird_speed_cnf = 1;
static unsigned int raised_speed_cnf = 1;

void bird_iterator(Bird *bird) {
    bird->y += _bird_speed_cnf * bird->vector;
    if (bird->vector == raise) {
        bird->raiseTime -= raised_speed_cnf;
    }
    if (bird->raiseTime <= BIRD_RAISE_TIME_MIN) {
        bird->raiseTime = BIRD_RAISE_TIME_DEFAULT;
        bird->vector = drop;
    }
    bird->time = (bird->time + 1) % 10;
    if (bird->time % 10 < 5) {
        bird->image = bird->image1;
    } else {
        bird->image = bird->image2;
    }
}

void bird_raise(Bird *bird) {
    bird->raiseTime = BIRD_RAISE_TIME_DEFAULT;
    bird->vector = raise;
}

void OLED_DrawBird(const Bird *bird) {
    OLED_DrawImage(bird->x, bird->y, bird->image, OLED_COLOR_NORMAL);
}

